package com.yz.controller;
import com.yz.core.exception.JsonException;
import com.yz.entity.CommentEntity;
import com.yz.entity.UserEntity;
import com.yz.service.ICommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpSession;
@Controller
@RequestMapping("/commentController")
public class CommentServlet{
    @Autowired
    private ICommentService commentService;
    @PostMapping ("/add/{id}")
    public String add(@PathVariable Integer id, CommentEntity commentEntity, HttpSession session){
        UserEntity loginUser = (UserEntity)session.getAttribute("loginUser");
        if (loginUser == null) {
            throw new JsonException(100, "请先登录");
        }
        commentEntity.setUserId(loginUser.getId());
        commentService.save(commentEntity);
        //重定向
        return "redirect:/invitataionController/info/" + id;
    }
}
